#ifndef CLEANINDEX_H
#define CLEANINDEX_H

#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include "ProtoFile.h"
#include "Disktools.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
#include "buffclass.h"
#include "bt_mutex.h"
#include "bt_thread.h"
#include "saft_deque.h"
#include "sndaconfig.h"

template<class T, class Toperation, class ToperationDelMark>
void cleanindex(std::string &src, std::string & dest)
{
    WriteProtoFile WpDestfile(dest);
    ReadProtoFile readfile(src);
    Toperation oper;
    ToperationDelMark deloper;
    T * oldpoint = NULL;
    while(1)
    {
        T * readobject = new T();
        
        if(!readfile.GetProject(*readobject))
        {
            break;
        }
        else
        {
            if(oldpoint == NULL)
            {
                oldpoint = readobject;
            }
            else
            {
                
                if(oper.euqal(oldpoint, readobject))
                {
                    delete oldpoint;
                    oldpoint = readobject;
                }
                else
                {
                    if(!deloper.euqal(oldpoint))
                    {
                        WpDestfile.SaveProject<T>(*oldpoint);
                    }
                    delete oldpoint;
                    oldpoint = readobject;
                }
            }
        }
        
    }
    if(oldpoint)
    {
        if(!deloper.euqal(oldpoint))
        {
            WpDestfile.SaveProject<T>(*oldpoint);
        }
        
        delete oldpoint;
    }
    
}
#endif
